﻿<phone:PhoneApplicationPage 
    x:Class="CetWin.Views.HistoriesView"
    x:Name="mainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:phoneExt="clr-namespace:Phone.Framework.Behaviors;assembly=Phone.Framework"
    xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
    xmlns:phoneExtConverters="clr-namespace:Phone.Framework.Converters;assembly=Phone.Framework"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    xmlns:cal="clr-namespace:Caliburn.Micro;assembly=Caliburn.Micro"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    mc:Ignorable="d" d:DesignHeight="696" d:DesignWidth="480"
    shell:SystemTray.IsVisible="True"
    phoneExt:AppBarButtonEnableBehavior.ButtonName="Clear">
    <phone:PhoneApplicationPage.Resources>
        <phoneExtConverters:TimeRangeConverter x:Key="TimeRangeConverter" />
        <DataTemplate x:Key="timeGroupHeader">
            <Border Background="{StaticResource PhoneAccentBrush}"
                    Padding="{StaticResource PhoneTouchTargetOverhang}">
                <TextBlock Text="{Binding Key,Converter={StaticResource TimeRangeConverter}}"
                           Style="{StaticResource PhoneTextLargeStyle}" />
            </Border>
        </DataTemplate>
        <DataTemplate x:Key="FavoriteItemTemplate">
            <StackPanel Orientation="Vertical">
                <TextBlock Text="{Binding Name}"
                           FontSize="{StaticResource PhoneFontSizeExtraLarge}" />
                <toolkit:ContextMenuService.ContextMenu>
                    <toolkit:ContextMenu x:Name="menu_Element">
                        <i:Interaction.Behaviors>
                            <phoneExt:MenuContextBehavior ElementName="mainPage" />
                        </i:Interaction.Behaviors>
                        <toolkit:MenuItem Header="I got it"
                                          cal:Message.Attach="[Event Click] = [Action RememberWord($this)]" />
                        <toolkit:MenuItem Header="Delete"
                                          cal:Message.Attach="[Event Click] = [Action DeleteHistory($this)]" />
                    </toolkit:ContextMenu>
                </toolkit:ContextMenuService.ContextMenu>
            </StackPanel>
        </DataTemplate>
    </phone:PhoneApplicationPage.Resources>
        <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">

        <controls:Pivot x:Name="pivot"
                        SelectedIndex="{Binding SelectedPivotIndex,Mode=TwoWay,FallbackValue=-1}"
                        cal:Message.Attach="[Event SelectionChanged] = [Action ChangePivot($this.SelectedIndex)]">
            <!--Pivot item one-->
            <controls:PivotItem Header="Favorites">
                <Grid x:Name="ContentPanel" Margin="12,0,12,0">
                    <toolkit:LongListSelector x:Name="favorites_Element"
                                      cal:Message.Attach="[Event SelectionChanged] = [Action OpenWordDetailView]"
                                      Background="Transparent"
                                              ItemsSource="{Binding Favorites,Mode=TwoWay}"
                                      GroupHeaderTemplate="{StaticResource timeGroupHeader}"
                                      ItemTemplate="{StaticResource FavoriteItemTemplate}">
                        <i:Interaction.Behaviors>
                            <phoneExt:LongListSelectorBehavior SelectedItem="{Binding SelectedItem,Mode=TwoWay}" />
                            <phoneExt:NoItemsSourceTipBehavior/>
                        </i:Interaction.Behaviors>
                    </toolkit:LongListSelector>
                </Grid>
            </controls:PivotItem>
            <!--Pivot item two-->
            <controls:PivotItem Header="Histories">
                <Grid Margin="12,0,12,0">
                    <ScrollViewer>
                        <ListBox ItemsSource="{Binding Histories,Mode=TwoWay}"
                                 SelectedItem="{Binding SelectedHistoryItem,Mode=TwoWay}"
                                 cal:Message.Attach="[Event SelectionChanged] = [Action OpenWordDetailView]">
                            <ListBox.ItemTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                        <Border Background="{StaticResource PhoneAccentBrush}"
                                                VerticalAlignment="Center"
                                                Width="50"
                                                Height="50">
                                            <TextBlock VerticalAlignment="Center" Foreground="White"
                                                       HorizontalAlignment="Center"
                                                       Text="{Binding Count}" />
                                        </Border>
                                        <TextBlock Text="{Binding Name}"
                                                   Margin="10,0,0,0"
                                                   FontSize="{StaticResource PhoneFontSizeExtraLarge}" />
                                </StackPanel>
                            </DataTemplate>
                            </ListBox.ItemTemplate>
                        <i:Interaction.Behaviors>
                            <phoneExt:NoItemsSourceTipBehavior />
                        </i:Interaction.Behaviors>
                        </ListBox>
                    </ScrollViewer>
                </Grid>
            </controls:PivotItem>
        </controls:Pivot>
    </Grid>
 
    <!--Sample code showing usage of ApplicationBar-->
    <phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
            <shell:ApplicationBar.Buttons>
                <!--<cal:AppBarButton IconUri="/Resources/Icons/voice.png"
                                  Text="Voice"
                                  Message="PlayVoice" />-->
                <cal:AppBarButton  IconUri="/Resources/Icons/appbar.delete.rest.png"
                                   Text="Clear" Message="Clear" />
            </shell:ApplicationBar.Buttons>
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>
    <i:Interaction.Behaviors>
        <phoneExt:MediaPlayBehavior />
    </i:Interaction.Behaviors>
</phone:PhoneApplicationPage>

<!--<ListBox x:Name="histories_Element"
         cal:Message.Attach="[Event SelectionChanged] = [Action OpenWordDetailView]"
         cal:Action.TargetWithoutContext="{Binding DataContext,ElementName=mainPage}"
         SelectedItem="{Binding SelectedItem,Mode=TwoWay}"
         ItemsSource="{Binding Histories}">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Vertical">
                <TextBlock Text="{Binding Name}"
                           FontSize="48" />
                <TextBlock Text="{Binding HistoryTime}"
                           FontSize="48" />

                <Button Click="Button_Click" Content="Delete" />
                            cal:View.Model="{Binding Tag,ElementName=menu_Element}" 
                                        cal:Message.Attach="[Event Click] = [Action SearchWithYoudao()]" Click="MenuItem_Click"
                            cal:Message.Attach="[Event Hold] = [Action DeleteHistory1($this)]"
                                    cal:Action.TargetWithoutContext="{Binding DataContext,ElementName=mainPage}"
                            
                <toolkit:ContextMenuService.ContextMenu>
                    <toolkit:ContextMenu x:Name="menu_Element">
                        <i:Interaction.Behaviors>
                            <phoneExt:MenuContextBehavior ElementName="mainPage" />
                        </i:Interaction.Behaviors>
                        <toolkit:MenuItem Header="Delete"
                                          cal:Message.Attach="[Event Click] = [Action DeleteHistory($this)]" />
                    </toolkit:ContextMenu>
                </toolkit:ContextMenuService.ContextMenu>
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>-->